﻿/*****************************************************************************/
/**
 *	\file	checkOut.cpp
 *	\author	Xavier
 *	\date	2023/05/07
 *	\version	1.0
 *	\brief	退房结算
 *	\note	Copyright (c) 2020-2030 南京理工大学
 *	\remarks	无
 ******************************************************************************/
#include "head.h"

void checkOut(CMgr *mgrobj)
{
    assert(NULL != mgrobj);
    char name2[10], id2[19];
    int standard, j, room_number, day1, day2, day;
Again004:
    cout << "请输入要退房的顾客姓名和身份证号码:\n";
    inputStr2(name2, sizeof(name2), id2, sizeof(id2));
    if (strlen(id2) != 18)
    {
        cout << "非身份证号码，请重新输入" << endl;
        goto Again004;
    }
    cout << "请输入该顾客实住天数:\n";
    day2 = inputINT();
    for (j = 0; j < mgrobj->i; j++)
    {
        if ((strcmp(mgrobj->customer[j]->get_name(), name2) == 0) &&
            (strcmp(mgrobj->customer[j]->get_ID(), id2) == 0))
        {
            room_number = mgrobj->customer[j]->get_room_number();
            standard = room_number / 100;
            day1 = mgrobj->customer[j]->get_day();
            day = day1 - day2;
            switch (standard)
            {
            case 6:
                cout << "顾客的房间号是" << room_number << " :为单人间,每天150元\n";
                cout << "该顾客预付了房费 " << mgrobj->customer[j]->get_prepaid() << "元, 实际消费 " << day2 * 150 << "元整!\n";
                cout << endl;
                if (day > 0)
                    cout << "请退给该顾客 " << day * 150 << " 元整!\n";
                if (day < 0)
                    cout << "请补收该顾客住房费 " << -day * 150 << " 元整!\n";
                break;
            case 7:
                cout << "顾客的房间号是" << room_number << " :为双人间,每天200元\n";
                cout << "该顾客预付了房费 " << mgrobj->customer[j]->get_prepaid() << "元, 实际消费 " << day2 * 200 << "元整!\n";
                cout << endl;
                if (day > 0)
                    cout << "请退给该顾客 " << day * 200 << " 元整!\n";
                if (day < 0)
                    cout << "请补收该顾客住房费 " << -day * 200 << " 元整!\n";
                break;
            case 8:
                cout << "顾客的房间号是" << room_number << " :为标准间,每天300元\n";
                cout << "该顾客预付了房费 " << mgrobj->customer[j]->get_prepaid() << "元, 实际消费 " << day2 * 300 << "元整!\n";
                cout << endl;
                if (day > 0)
                    cout << "请退给该顾客 " << day * 300 << " 元整!\n";
                if (day < 0)
                    cout << "请补收该顾客住房费 " << -day * 300 << " 元整!\n";
                break;
            case 9:
                cout << "顾客的房间号是" << room_number << " :为总统套房,每天600元\n";
                cout << "该顾客预付了房费 " << mgrobj->customer[j]->get_prepaid() << "元, 实际消费 " << day2 * 600 << "元整!\n";
                cout << endl;
                if (day > 0)
                    cout << "请退给该顾客 " << day * 600 << " 元整!\n";
                if (day < 0)
                    cout << "请补收该顾客住房费 " << -day * 600 << " 元整!\n";
                break;
            }
            cout << endl;
            cout << "退房核算清楚,请按1: ";
        Again001:
            char account = inputChar();
            if (account == '1')
            {
                for (int k = 0; k < 80; k++)
                {
                    if (mgrobj->room[k].number == mgrobj->customer[j]->get_room_number())
                        mgrobj->room[k].state = 0;
                }
                mgrobj->i--;
                for (; j < mgrobj->i; j++)
                {
                    mgrobj->customer[j] = mgrobj->customer[j + 1];
                }
                delete mgrobj->customer[mgrobj->i];
            }
            else
            {
                cout << "输入有误，请重试" << endl;
                goto Again001;
            }
        }
    }
}